﻿<template>
  <a-card :bordered="false">
    <div class="table-operator"></div>

    <div class="table-page-search-wrapper">
      <div class="table-page-search-wrapper" style="text-align: right">
        <a-input v-model="queryParam.keyword" style="width: 20%" placeholder="请输入客户名称" />

        <a-button
          type="primary"
          icon="search"
          style="margin-left: 8px"
          @click="
            () => {
              this.pagination.current = 1
              this.getDataList()
            }
          "
        >
          搜索
        </a-button>

        <a-button
          icon="search"
          style="margin-left: 8px"
          @click="
            () => {
              if (this.divistrue) {
                this.divistrue = false
              } else {
                this.divistrue = true
              }
            }
          "
          >高级搜索</a-button
        >
        <a-button style="margin-left: 8px" icon="redo" @click="() => (queryParam = {})">重置</a-button>
        <a-button
          type="primary"
          style="margin-left: 8px"
          v-if="hasPerm('merchant.Add')"
          icon="plus"
          @click="hanldleAdd()"
          >新建</a-button
        >
        <a-button
          v-if="hasPerm('merchant.Delete')"
          type="danger"
          style="margin-left: 8px"
          icon="minus"
          @click="handleDelete(selectedRowKeys)"
          :disabled="!hasSelected()"
          :loading="loading"
          >删除</a-button
        >
        <a-button type="primary" icon="redo" style="margin-left: 8px" @click="getDataList()">刷新</a-button>
      </div>
    </div>

    <a-drawer :width="500" title="高级筛选" placement="top" :visible="divistrue" @close="onClose">
      <a-row>
        <a-col :span="8"
          >客户&emsp;名称&emsp;<a-input
            v-model="queryParam.keyword"
            placeholder="请输入客户名称"
            style="width: 80%"
          ></a-input
        ></a-col>
        <a-col :span="8"
          >税&emsp;&emsp;&emsp;号&emsp;<a-input
            v-model="queryParam.customTaxIdcd"
            style="width: 80%"
            placeholder="请输入税号"
          ></a-input
        ></a-col>

        <a-col :span="8"
          >法人&emsp;姓名&emsp;<a-input
            v-model="queryParam.customLegalPerson"
            style="width: 80%"
            placeholder="请输入法人姓名"
          ></a-input
        ></a-col>
      </a-row>
      <a-row style="margin-top: 10px">
        <a-col :span="8"
          >法人证件号&emsp;<a-input
            v-model="queryParam.IdNumber"
            placeholder="请输入法人证件号"
            style="width: 80%"
          ></a-input
        ></a-col>
        <a-col :span="8"
          >联系人姓名&emsp;<a-input
            v-model="queryParam.customCollector"
            style="width: 80%"
            placeholder="请输入联系人姓名"
          ></a-input
        ></a-col>

        <a-col :span="8"
          >联系人电话&emsp;<a-input
            v-model="queryParam.customCollectorPhone"
            style="width: 80%"
            placeholder="请输入联系人电话"
          ></a-input
        ></a-col>
      </a-row>
      <a-row style="margin-top: 10px">
        <a-col :span="8"
          >状&emsp;&emsp;&emsp;态&emsp;
          <a-select v-model="queryParam.Status" placeholder="请选择审核状态" style="width: 80%">
            <a-select-option value="">全部数据</a-select-option>
            <a-select-option value="1">已审核</a-select-option>
            <a-select-option value="0">未审核</a-select-option>
          </a-select>
        </a-col>
      </a-row>

      <div style="text-align: right; margin-top: 30px">
        <a-button @click="onClose" icon="close">关闭</a-button>
        <a-button
          type="primary"
          style="margin-left: 8px"
          icon="search"
          @click="
            () => {
              this.pagination.current = 1
              this.getDataList()
              this.divistrue = false
            }
          "
          >查询</a-button
        >
      </div>
    </a-drawer>

    <a-table
      ref="table"
      :columns="columns"
      :rowKey="(row) => row.Id"
      :dataSource="data"
      :pagination="pagination"
      :loading="loading"
      @change="handleTableChange"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      :bordered="false"
      size="middle"
    >
      <template slot="CheckStatus" slot-scope="text">
        <span v-if="text == 0"><a-tag color="blue">待审核</a-tag></span>
        <span v-else-if="text == 1"><a-tag color="green">审核通过</a-tag></span>
        <span v-else><a-tag color="red">审核未通过</a-tag></span>
      </template>
      <span slot="action" slot-scope="text, record">
        <template>
          <a @click="handleEdit(record.Id)" v-if="hasPerm('merchant.Edit')">编辑</a>
          <a-divider type="vertical" />
          <a-popconfirm
            title="确定删除吗？"
            v-if="hasPerm('merchant.Delete')"
            ok-text="确定"
            cancel-text="取消"
            @confirm="handleDelete([record.Id])"
            @cancel="cancel"
          >
            <a href="#">删除</a>
          </a-popconfirm>
          <a-divider type="vertical" />
          <a @click="handleCheck(record.Id)" v-if="hasPerm('merchant.Check') && record.CheckStatus != 1">审核</a>
        </template>
      </span>
    </a-table>

    <edit-form ref="editForm" :parentObj="this"></edit-form>
  </a-card>
</template>

<script>
import EditForm from './EditForm'

const columns = [
  { title: '客户名称', dataIndex: 'customerName', width: '15%' },
  { title: '负责人', dataIndex: 'customLegalPerson', width: '15%' },
  { title: '联系人电话', dataIndex: 'customCollectorPhone', width: '15%' },
  { title: '添加时间', dataIndex: 'CreateTime', width: '15%' },
  { title: '审核状态', dataIndex: 'CheckStatus', width: '15%', scopedSlots: { customRender: 'CheckStatus' } },
  { title: '操作', dataIndex: 'action', scopedSlots: { customRender: 'action' } },
]

export default {
  components: {
    EditForm,
  },
  mounted() {
    this.getDataList()
  },
  data() {
    return {
      divistrue: false,
      data: [],
      pagination: {
        current: 1,
        pageSize: 10,
        showTotal: (total, range) => `总数:${total} 当前:${range[0]}-${range[1]}`,
      },
      filters: {},
      sorter: { field: 'Id', order: 'asc' },
      loading: false,
      columns,
      queryParam: {},
      selectedRowKeys: [],
    }
  },
  methods: {
    onClose() {
      this.divistrue = false
    },
    handleTableChange(pagination, filters, sorter) {
      this.pagination = { ...pagination }
      this.filters = { ...filters }
      this.sorter = { ...sorter }
      this.getDataList()
    },
    getDataList() {
      this.selectedRowKeys = []

      this.loading = true
      this.$http
        .post('/Base_leasesystem_merchant/leasesystem_merchant/GetHeightSearch', {
          PageIndex: this.pagination.current,
          PageRows: this.pagination.pageSize,
          SortField: this.sorter.field || 'Id',
          SortType: this.sorter.order,
          Search: this.queryParam,
          ...this.filters,
        })
        .then((resJson) => {
          this.loading = false
          this.data = resJson.Data.Data

          const pagination = { ...this.pagination }
          pagination.total = resJson.Data.Total
          this.pagination = pagination
        })
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    hasSelected() {
      return this.selectedRowKeys.length > 0
    },
    hanldleAdd() {
      this.$refs.editForm.openForm()
    },
    handleEdit(id) {
      this.$refs.editForm.openForm(id)
    },
    handleCheck(id) {
      this.$refs.editForm.openForm(id, '审核')
    },
    handleDelete(ids) {
      var thisObj = this

      return new Promise((resolve, reject) => {
        thisObj.$http.post('/Base_leasesystem_merchant/leasesystem_merchant/DeleteData', ids).then((resJson) => {
          resolve()

          if (resJson.Success) {
            thisObj.$message.success('操作成功!')

            thisObj.getDataList()
          } else {
            thisObj.$message.error(resJson.Msg)
          }
        })
      })
    },
    cancel(e) {
      this.$message.error('已取消删除')
    },
  },
}
</script>

<style>
.ant-table-thead > tr > th {
  font-weight: 600;
  color: #333333;
}
#components-form-demo-advanced-search .ant-form {
  max-width: 100%;
}

[data-theme='dark'] .ant-advanced-search-form {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid #434343;
  padding: 24px;
  border-radius: 2px;
}
</style>